package com.learn.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;


/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/08/01
 * @description ch07 断路器
 * 模拟异常
 */
@RestController
public class PayCircuitController {
    @GetMapping("/pay/circuit/{id}")
    public String circuit(@PathVariable("id") Integer id) {
        System.out.println(Thread.currentThread().getName() + "\t" + "enter the pay method!!!");
        if(id<1) {
            throw new RuntimeException("id must be positive!..................");
        } else if (id == 9999) {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        return "OK, id: " + id + "..................";
    }
}
